package yjl.spec.edu.week11_home01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class firstActivity extends AppCompatActivity {
    private List<Listmesg> listListmesg = new ArrayList<Listmesg>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);

        initLisemesgs(); // 初始化数据

        ListAdapter adapter = new ListAdapter(firstActivity.this, R.layout.list_item, listListmesg);
        ListView listView = (ListView) findViewById(R.id.list_view);

        listView.setAdapter(adapter);
        
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                Listmesg listMesg = listListmesg.get(position);
                Toast.makeText(firstActivity.this, listMesg.getMesg(), Toast.LENGTH_SHORT).show();
            }
        });

    }
    private void initLisemesgs() {

        for (int i = 0; i < 2; i++) {
            Listmesg mesg1 = new Listmesg("订阅号消息","小新说车：什么是小众的豪华",R.drawable.wechat13);
            listListmesg.add(mesg1);
            Listmesg mesg2 = new Listmesg("指云端","这个秋冬她们相继离世，癌症究竟是怎样摧...",R.drawable.wechat2);
            listListmesg.add(mesg2);
            Listmesg mesg3 = new Listmesg("微信收款助手","微信支付收款4.00元",R.drawable.wechat3);
            listListmesg.add(mesg3);
            Listmesg mesg4 = new Listmesg("金大师为民服务","机构师说：[语音]",R.drawable.wechat4);
            listListmesg.add(mesg4);
            Listmesg mesg5 = new Listmesg("春晖花园客服中心","[10条]春晖花园客服中心：@3_1_903水 有",R.drawable.wechat5);
            listListmesg.add(mesg5);
            Listmesg mesg6 = new Listmesg("H161师晨冰 涨价逻辑交流群","Aa严师高级助理小胡（胡文涛）：[太阳]...",R.drawable.wechat6);
            listListmesg.add(mesg6);
            Listmesg mesg7 = new Listmesg("微信团队","登录操作通知",R.drawable.wechat7);
            listListmesg.add(mesg7);
            Listmesg mesg8 = new Listmesg("幼专教工足球协会","1231414",R.drawable.wechat8);
            listListmesg.add(mesg8);
        }
    }
}
